﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Build;
using Microsoft.Build.Evaluation;
using PreBuildStep.Properties;

namespace PreBuildStep
{
    class Program
    {
        static int Main(string[] args)
        {
            using(var sr = new StreamWriter("prebuild.log", false))
            {
                sr.WriteLine("{0}", args[0]);

                var filename = Path.GetDirectoryName(args[0]) + @"\generated.ebc.cs";
                File.WriteAllText(filename, Resources.CodeToGenerate);
                

                var prj = new Project(args[0]);
                sr.WriteLine("items: {0}", prj.Items.Count);
                sr.WriteLine("namespace: {0}", prj.Properties.Where(p => p.Name == "RootNamespace").Select(p => p.EvaluatedValue).First());
                prj.Items.ToList().ForEach(g =>
                                               {
                                                   sr.WriteLine("item type: {0}", g.ItemType);
                                                       sr.WriteLine("  content: {0}", g.EvaluatedInclude);
                                               });


                Trace.TraceInformation("trace info");
                Console.WriteLine("hallo!");
                Console.Error.WriteLine("Schwerer Fehler");

                return 0;
            }
        }
    }
}
